"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var PDAScan = /** @class */ (function () {
    function PDAScan(options) {
        this._codeQueryTag = false;
        this.broadcast = options.broadcast;
        this.broadcastExtraString = options.broadcastExtraString;
        this.onReceive = options.onReceive;
        this.initScan();
    }
    // 初始化
    PDAScan.prototype.initScan = function () {
        var _this = this;
        this.main = plus.android.runtimeMainActivity(); //获取activity
        var IntentFilter = plus.android.importClass("android.content.IntentFilter");
        this.filter = new IntentFilter();
        this.filter.addAction(this.broadcast); // 广播动作
        this.receiver = plus.android.implements("io.dcloud.feature.internal.reflect.BroadcastReceiver", {
            onReceive: function (context, intent) {
                plus.android.importClass(intent);
                var code = intent.getStringExtra(_this.broadcastExtraString); // 广播标签
                _this.queryCode(code);
            },
        });
    };
    // 注册监听
    PDAScan.prototype.startScan = function () {
        this.main.registerReceiver(this.receiver, this.filter);
    };
    // 取消监听
    PDAScan.prototype.stopScan = function () {
        this.main.unregisterReceiver(this.receiver);
    };
    PDAScan.prototype.queryCode = function (code) {
        var _this = this;
        //防重复
        if (this._codeQueryTag)
            return false;
        this._codeQueryTag = true;
        setTimeout(function () {
            _this._codeQueryTag = false;
        }, 150);
        this.onReceive(code);
    };
    return PDAScan;
}());
exports.default = PDAScan;
